using UnityEngine;

public class UI_Dynamic : MyCanvasGrounp
{
    public float Width { get; protected set; }
    public float Height { get; protected set; }
    protected RectTransform rectTransform;
    protected Transform m_transform;

    protected override void Awake()
    {
        base.Awake();
        m_transform = transform;
        rectTransform = GetComponent<RectTransform>();
        Width = rectTransform.rect.width / 800 * Screen.width;
        Height = rectTransform.rect.height / 450 * Screen.height;
    }

    protected virtual void Move(Vector2 position, float offset = 0)
    {
        float x, y;
        x = position.x + offset + Width < Screen.width ? position.x + offset : position.x - offset - Width;
        y = position.y - Height > 0 ? position.y : position.y + Height;
        m_transform.position = new Vector2(Mathf.Clamp(x, 0, Screen.width - Width), Mathf.Clamp(y, Height, Screen.height));
    }
}
